import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-04-21
 * Time: 18:04
 */
public class Binsearch {
    public static int search(int[] arr,int x) {
        int left = 0;
        int right = arr.length - 1;
        while(left <= right) {
            int m = (left + right)/2;
            if(arr[m] > x) {
                right = m - 1;
            }
            if(arr[m] < x) {
                left = m +1;
            }
            if(arr[m] == x) {
                return m;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] arr = {1,12,13,3,11,6,9,7,8,5,2};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        int x = search(arr,12);
        System.out.println(x);
    }
}
